package com.renwu.edu.info.manager.dao;

import com.renwu.edu.info.manager.domain.Student;

public class StudentDao {
    private static Student[] stus = new Student[5];

    public boolean AddStudent(Student stu) {
        int index = -1;
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] == null) {
                index = i;
                break;
            }
        }
        if (index == -1) {
            return false;
        } else {
            stus[index] = stu;
            return true;
        }
    }

    public Student[] findAllStudent() {
        return stus;
    }

    public int getIndex(int id) {
        int index = -1;
        for (int i = 0; i < stus.length; i++) {
            if(stus[i] != null && stus[i].getId() == id){
                index = i;
                break;
            }
        }
        return index;
    }

    public void deleteStudent(int deleteId) {
        int index = getIndex(deleteId);
        stus[index] = null;
    }


    public void setStudent(int setId, Student newStu) {
        int index = getIndex(setId);
        stus[index] = newStu;
    }
}
